<template>
  <div class="login-container">
    <el-form ref="loginForm"
             :model="loginForm"
             :rules="rules"
             class="login-form"
             autocomplete="on">

      <div class="title-container"
           style="text-align:center;">
        <div class="title">泓海茶业</div>
      </div>

      <el-form-item label="账号"
                    prop="username">
        <el-input v-model="loginForm.username"
                  clearable
                  placeholder="请输入账号"
                  @change="username_input_change()"
                  @blur="username_input_blur()" />
      </el-form-item>

      <el-form-item label="密码"
                    prop="password">
        <el-input v-model="loginForm.password"
                  placeholder="请输入密码"
                  @blur="password_input_blur()"
                  show-password />
      </el-form-item>

      <el-button :loading="loading"
                 type="primary"
                 style="width:100%;margin:20px 0;"
                 @click.native.prevent="handleLogin">立即登入</el-button>
      <div class="tips"><i class="el-icon-question" /> 如忘记密码请联系上级重置</div>
    </el-form>

  </div>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      group_list: [],
      group_id: null,
      loginForm: {
        username: '',
        password: '',
      },
      rules: {
        username: [
          { required: true, message: '请输入帐号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      },
      loading: false,
      redirect: undefined,
      otherQuery: {}
    }
  },

  created () {

  },
  mounted () {


  },
  methods: {
    handleLogin () {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.loading = true
          this.$store
            .dispatch('user/login', this.loginForm)
            .then((res) => {
              this.$router.push({
                path: this.redirect || '/',
                query: this.otherQuery
              })
              this.loading = false
            })
            .catch((res) => {
              if (res.code != 200) {
                this.$message.error(res.msg)
              }
              this.loading = false
            })
        } else {
          return false
        }
      })
    }

  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;
$light_gray: #fff;
$cursor: #fff;
</style>

<style lang="scss" scoped>
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  background: url("~@/assets/bg2.jpg") no-repeat;
  background-size: 100% 100%;
  height: 100%;
  width: 100%;
  overflow: hidden;
  .login-form {
    border-radius: 10px;
    background-color: #fff;
    position: absolute;
    right: 200px;
    width: 430px;
    max-width: 100%;
    padding: 55px;
    top: 180px;
    overflow: hidden;
    .title-container {
      position: relative;
      .title {
        font-size: 26px;
        color: #000;
        font-weight: bold;
      }
    }

    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }

    .tips {
      margin-top: 10px;
      width: 100%;
      font-size: 12px;
      color: #889aa4;
      text-align: center;
    }
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}
</style>
